const demoModel = require("./schema/demoSchema")

// 新增项目
module.exports.addDemoDao = async function (newDemoInfo) {
    const data = await demoModel.create(newDemoInfo);
    return data;
}


// 查询所有的项目
module.exports.findAllDemoDao = async function () {
    const data = await demoModel.find()
    return data.map(demo => demo.toJSON());
}

// 修改项目
module.exports.updateDemoDao = async function(id, newDemoInfo){
    await demoModel.replaceOne({_id:id},{
      ...newDemoInfo
    });
    return await demoModel.findOne({_id:id});
}

// 删除项目
module.exports.deleteDemoDao = async function(id){
    return await demoModel.deleteOne({_id:id})
}